package com.cat.dynamicPlanning02;

import java.util.stream.IntStream;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/find-the-maximum-length-of-valid-subsequence-i/?envType=problem-list-v2&envId=dynamic-programming
 * @create 2025/11/5 16:21
 * @since JDK17
 */

public class Solution40 {
    public int maximumLength(int[] nums) {
        int ans = 0, n = nums.length, odd = 0, even = 0;
        for (int i = 0; i < n; i++) {
            nums[i] %= 2;
            odd += nums[i];
            even += 1 - nums[i];
        }
        for (int i = 0, j = 0; j < n; i = j) {
            while (j < n && nums[i] == nums[j]) {
                j++;
            }
            ans++;
        }
        return IntStream.of(ans, odd, even).max().getAsInt();
    }
}